//
//  TrimFromTo3.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/21.
//

import SwiftUI

struct TrimFromTo3: View {
    var body: some View {
        Text("顺着线条绘制方向,从起始点到到终点按照比例绘,圆形默认原点是圆心水平右侧,")
      TrimmedCircle()
      TrimmedBezierPath()
    }
}

#Preview {
    TrimFromTo3()
}

struct TrimmedCircle: View {
  var body: some View {
    Circle()
      .trim(from: 0.25, to: 0.75)
      .stroke(Color.blue, lineWidth: 5)
      .frame(width: 200, height: 200)
      .background(Color(.systemGray4))
  }
}
struct TrimmedBezierPath: View {
  var body: some View {
    Path { path in
      path.move(to: CGPoint(x: 50, y: 150))
      path.addCurve(to: CGPoint(x: 250, y: 150),
                    control1: CGPoint(x: 100, y: 0),
                    control2: CGPoint(x: 200, y: 300))
    }
    .trim(from: 0.25, to: 0.75)
    .stroke(Color.red, lineWidth: 5)
    .frame(width: 300, height: 300)
    .background(Color(.systemGray4))

  }
}
